#if !defined(MutexHeader)
#define MutexHeader

#include <pthread.h>

class Mutex {
public:
  Mutex () {
    pthread_mutex_init (&mutex, 0);
  }
  ~Mutex () {
    pthread_mutex_destroy (&mutex);
  }

  void lock () {
    pthread_mutex_lock (&mutex);
  }
  void unlock () {
    pthread_mutex_unlock (&mutex);
  }

  pthread_mutex_t mutex;
};

class ReadWriteLock {
public:
  ReadWriteLock () {
    pthread_rwlock_init (&rwlock, 0);
  }
  ~ReadWriteLock () {
    pthread_rwlock_destroy (&rwlock);
  }

  void lockRead () {
    pthread_rwlock_rdlock (&rwlock);
  }
  void unlockRead () {
    pthread_rwlock_unlock (&rwlock);
  }

  void lockWrite () {
    pthread_rwlock_wrlock (&rwlock);
  }
  void unlockWrite () {
    pthread_rwlock_unlock (&rwlock);
  }

  pthread_rwlock_t rwlock;
};

#endif
